package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.Log;
import com.itheima.mapper.LogMapper;
import com.itheima.service.db.LogService;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class LogServiceImpl implements LogService {
    @Autowired
    private LogMapper logMapper;

    /**
     * 保存日志对象
     * @param log
     */
    @Override
    public void save(Log log) {
        logMapper.insert(log);
    }

    /**
     * 查询所有日志列表
     * @return
     * @param pageNum
     * @param pageSize
     */
    @Override
    public PageBeanVo findLogList(Integer pageNum, Integer pageSize,Long userId) {
        IPage page = new Page(pageNum,pageSize);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id",userId);
        if (userId==null){
            queryWrapper = null;
        }
        page = logMapper.selectPage(page ,queryWrapper);
        return new PageBeanVo(pageNum,pageSize,page.getTotal(),page.getRecords());
    }

    /**
     * 删除日志
     * @param id
     */
    @Override
    public void deleteLog(Long id) {
        logMapper.deleteById(id);

    }



}